﻿using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace OpenShape
{
    static class  LayerManager
    {
        public static List<Layer> m_Layers = new List<Layer>();

        public static void AddLayer(string filename, string fType)
        {
            m_Layers.Add(new Layer());
            if (fType == "shp")
                m_Layers[m_Layers.Count - 1].OpenFile(filename, "shp");
            else if (fType == "dbf")
                m_Layers[m_Layers.Count - 1].OpenFile(filename, "dbf");
            else
                MessageBox.Show("지원하지 않는 형식입니다.");
        }

        public static void RemoveLayer(int index)
        {
            if (index >= m_Layers.Count)
                return;

            m_Layers.RemoveAt(index);
        }

        public static void MoveLayer(int SelectIndex, int MoveIndex)
        {
            Layer temp = new Layer();
            if (SelectIndex < MoveIndex)
            {
                temp = m_Layers[SelectIndex];
                for (int i = SelectIndex; i < MoveIndex; i++)
                {
                    m_Layers[i] = m_Layers[i + 1];
                }
                m_Layers[MoveIndex] = temp;
            }
            else
            {
                temp = m_Layers[MoveIndex];
                for (int i = MoveIndex; i < SelectIndex; i++)
                {
                    m_Layers[i] = m_Layers[i + 1];
                }
                m_Layers[SelectIndex] = temp;
            }
        }

        public static void DrawLayers(Graphics g, Scaler sc)
        {
            for (int i = 0; i < m_Layers.Count; i++)
            {
                m_Layers[i].Draw(g, sc);
            }
            for (int i = 0; i < m_Layers.Count; i++)
            {
                m_Layers[i].LayerLabelDraws(g, sc);
            }
        }

        private static void LayerOff(int index)
        {
            if (index >= m_Layers.Count)
                return;

            m_Layers[index].m_isOn = false;
        }

        private static void LayerOn(int index)
        {
            if (index >= m_Layers.Count)
                return;

            m_Layers[index].m_isOn = true;
        }

    }
}
